package com.xiaomeng.principle.inversion;

public class DependecyInversion {

    public static void main(String[] args) {

    }
}

/*// 方式1:通过接口传递实现依赖
// 开关的接口
interface IOpenAndClose {
    // 抽象方法,接收接口
    public void open(ITV tv);
}
interface ITV {
    public void play();
}
// 实现接口
class OpenAndClose implements IOpenAndClose {
    @Override
    public void open(ITV tv) {
        tv.play();
    }
}*/

/*// 方式2:通过构造方法传递依赖
interface IOpenAndClose {
    public void open(); // 抽象方法
}
interface ITV {  // ITV接口
    public void play();
}
class OpenAndClose implements IOpenAndClose {
    public ITV tv;  // 成员
    public OpenAndClose (ITV tv) {
        this.tv = tv;
    }
    @Override
    public void open() {
        this.tv.play();
    }
}*/

interface IOpenAndClose {
    public void open(); // 抽象方法
    public void setTv(ITV tv);
}
interface ITV {
    public void play();
}
class OpenAndClose implements IOpenAndClose {
    private ITV tv;
    @Override
    public void setTv(ITV tv) {
        this.tv = tv;
    }
    @Override
    public void open() {
        this.tv.play();
    }
}


